package com.gitee.wsl.common.ui.symbol


import androidx.compose.ui.graphics.Path
import com.gitee.wsl.base.tuple
import com.gitee.wsl.common.ui.base.Point
import com.gitee.wsl.common.ui.base.moveDown
import com.gitee.wsl.common.ui.base.moveLeft
import com.gitee.wsl.common.ui.base.moveRight
import com.gitee.wsl.common.ui.base.moveUp
import com.gitee.wsl.common.ui.ext.path.lineTo
import com.gitee.wsl.common.ui.ext.path.moveTo
import com.gitee.wsl.mathematics.geometry.shape.Arc
import com.gitee.wsl.unit.angle.AngleUnit
import com.gitee.wsl.unit.angle.ext.getPoint
import com.gitee.wsl.unit.angle.isWest
import com.gitee.wsl.unit.angle.quadrant
import com.gitee.wsl.unit.angle.toRadians

fun Symbol.Companion.arc(center: Point,
               radius: Float = 0.0f,
               startAngle: AngleUnit = 0.0f.toRadians(),
               sweepAngle: AngleUnit = 0.0f.toRadians(),
               linkCenter: Boolean = true) = Arc(center, radius, startAngle, sweepAngle, linkCenter)


fun Arc.arcLabelLine( textTitleWidth:Int,
                      textTitleHeight:Int,
                      pointToCircle: Int = 20,
                      titleLineToPDistance: Int = 20,
                      mTitleMarginStar: Int = 10):Triple<Path,Point,Point>{
   val line = Path()
   val firstPoint = halfAngle.getPoint(center, radius + pointToCircle)
   val midPoint =  halfAngle.getPoint(center, radius + pointToCircle + titleLineToPDistance)

   val quadrant = halfAngle.quadrant

   val endPoint = when{
       quadrant.isWest()-> {
           midPoint.moveLeft((mTitleMarginStar+textTitleWidth).toFloat())
       }
       else -> {
           midPoint.moveRight((mTitleMarginStar+textTitleWidth).toFloat())
       }
   }

    val topTextPoint = when{
        quadrant.isWest()-> {
            endPoint.moveUp(textTitleHeight+mTitleMarginStar.toFloat())
        }
        else -> {
            midPoint.moveRight((mTitleMarginStar).toFloat()).moveUp(textTitleHeight+mTitleMarginStar.toFloat())
        }
    }

    val bottomTextPoint= when{
        quadrant.isWest()-> {
            endPoint.moveDown(textTitleHeight+mTitleMarginStar.toFloat())
        }
        else -> {
            midPoint.moveRight((mTitleMarginStar).toFloat()).moveDown(textTitleHeight+mTitleMarginStar.toFloat())
        }
    }

    line.moveTo(firstPoint)
    line.lineTo(midPoint)
    line.lineTo(endPoint)

    line.circle(firstPoint,pointToCircle/4f)

    return tuple(line , topTextPoint , bottomTextPoint)

}

